//
//  CommonDatePickerViewController.m
//  KIASupervisory
//
//  Created by tan_xin on 14-7-17.
//  Copyright (c) 2014年 MyCompany. All rights reserved.
//

#import "CommonDatePickerViewController.h"

@interface CommonDatePickerViewController ()

@property (weak, nonatomic) IBOutlet UIDatePicker *datePicker;

- (IBAction)dismissPickerAction:(id)sender;
- (IBAction)cancelPickAction:(id)sender;
- (IBAction)confirmSelectDateAction:(id)sender;

@end

@implementation CommonDatePickerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.datePicker.backgroundColor = [UIColor lightGrayColor];
    self.datePicker.alpha = 1.0;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)dismissPickerAction:(id)sender {
    [self.view removeFromSuperview];
    if ([self parentViewController] != nil) {
        [self removeFromParentViewController];
    }
}

- (IBAction)cancelPickAction:(id)sender {
    [self dismissPickerAction:nil];
}

- (IBAction)confirmSelectDateAction:(id)sender {
    [self dismissPickerAction:nil];
    
    if (_delegate && [_delegate respondsToSelector:@selector(picker:didSelectedDate:)]) {
        [self.delegate picker:self didSelectedDate:self.datePicker.date];
    }
}
@end
